
#include"UdpCline.hpp"
#define SOC(v) (sockaddr*)(v)
#define default_size 1024

using namespace ThreadMoudle;

int main(int argc,char* argv[])
{
    if(argc!=3)
    {
        perror("缺少端口参数\n");
        exit(1);
    }

    //用户指定IP地址和端口号
    std::string serverip=argv[1];
    uint16_t serveerport=std::stoi(argv[2]);

    int sockfd=::socket(AF_INET,SOCK_DGRAM,0);
    if(sockfd<0)
    {
        std::cerr<<"socket creat is error"<<std::endl;
        exit(2);
    }

    std::cout<<"creat socket success"<<sockfd<<std::endl;

    struct sockaddr_in server;
    memset(&server,0,sizeof(server));
    server.sin_family=AF_INET;
    server.sin_addr.s_addr=inet_addr(serverip.c_str());
    server.sin_port=htons(serveerport);

    
    ThreadData td(sockfd,server);
    Thread<ThreadData> recver(RecverRoutine,td);
    Thread<ThreadData> sender(SendRoutine,td);

    recver.Start();
    sender.Start();

    recver.Join();
    sender.Join();
    close(sockfd);

    return 0;

}